<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Upload"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
        >导出
        </el-button>
      </el-col>
      <right-toolbar @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
        :data="categoryList"
        style="width: 100%"
        row-key="id"
        border
        lazy
        :load="fetchData"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="name" label="分类名称"/>
      <el-table-column prop="imageUrl" label="图标" #default="scope">
        <img :src="scope.row.imageUrl" width="50"/>
      </el-table-column>
      <el-table-column prop="orderNum" label="排序"/>
      <el-table-column prop="status" label="状态" #default="scope">
        {{ scope.row.status == 1 ? '正常' : '停用' }}
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"/>
    </el-table>
  </div>
</template>

<script setup name="Category">
//==================1.导入区域=====================
import {getTreeList} from '@/api/product/category'

//==================2.变量区域=====================

//定义页面显示的数据
const categoryList = ref([]);

//数据列表
const fetchData = async (row, treeNode, resolve) => {
  // 向后端发送请求获取数据
  const {code, msg, data} = await getTreeList(row.id)

  // 返回数据
  resolve(data)
}

//==================3.事件处理区域==================

//查询数据
function getList() {
  getTreeList(0).then(result => {
    categoryList.value = result.data
  })
}

//点击页面就加载数据
getList()

</script>